package com.bunkerdev.mymo;

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.SeekBar;

public class MyMOActivity extends Activity implements OnClickListener {
    /** Called when the activity is first created. */

    
    private Reproductor reproductor;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Button b1= (Button) findViewById(R.id.button1);
        b1.setOnClickListener(this);
        
        Button b2= (Button) findViewById(R.id.button2);
        b2.setOnClickListener(this);
        
        final SeekBar seekBar=  (SeekBar) findViewById(R.id.seekBar1);
        //TODO poner el max del seekbar y probar que se actualiza
       
		reproductor= new ReproductorImpl(Environment.getExternalStorageDirectory()+"/mymo/cache.mymo");

				new Thread() {

		            public void run() {
		        		try {
		        			while(true){
		        				Thread.sleep (1000);
		        				seekBar.setProgress(reproductor.getPosition());
		        			}
		        			} catch (Exception e) {
		        			// Mensaje en caso de que falle
		        			}
		                
		            }
		        }.start();

        
    }

	public void onClick(View v) {
		int i=v.getId();
		if(i==R.id.button1){
			Log.i("Button1"," as");
			new Thread() {

	            public void run() {
	            	Utilities.downloadFile("http://cs1320.vkontakte.ru/u7548411/audio/cd1541838b31.mp3");
	            }
	        }.start();
			
		}else if(i==R.id.button2){
			reproductor.play();
			Log.i("Button2"," adcdds");
		}
		
	}
}